﻿
$("#cprovince li a").each(function(index, element) {
    var title = $(this).attr("title");
    var t = false;
    for (var i = 0; i < ztocity.length; i++) {
        if (title == ztocity[i].Name && ztocity[i].Order == "1") {
            t = true;
            break;
        }
    }
    if (t == false) {
        $(this).addClass("not");
    }
});


$("#provinceNav li").click(function () {
    var index = $(this).index();
    $(this).parent().find(".Triangle").remove(),
	$(this).prepend('<div class="Triangle">&nbsp;</div>'),
	$(this).parent().find("li").removeClass("curr"),
	$(this).addClass("curr"),
	$(".provinceMain>li").removeClass("curr"),
	$(".provinceMain>li").eq(index).addClass("curr");
});

$("#chotcity li a").click(function () {
        $("#chotcity,#cprovince").find("a").removeClass("curr"),
        $(this).addClass("curr"),
        $(".provinceMain>li").removeClass("curr"),
        $(".provinceMain>li").eq(2).addClass("curr"),
        $("#provinceNav li").removeClass("curr"),
        $("#provinceNav li").find(".Triangle").remove(),
        $("#provinceNav li").eq(2).prepend('<div class="Triangle">&nbsp;</div>'),
        $("#provinceNav li").eq(2).addClass("curr");
        var city = $(this).attr("title").split("-")[1],
        content = "";
        for (var i = 0,
        len = ztoarea.length; i < len; i++) if (city == ztoarea[i].Name) {
            var data = ztoarea[i].Data;
            for (a = 0, alen = data.length; a < alen; a++) if (data[a].Order == "1") {
                content += "<li> <a title=\"" + $(this).attr("title") + "-" + data[a].Name + "\">" + data[a].Name + "</a></li>";
            } else {
                content += "<li> <a title=\"" + $(this).attr("title") + "-" + data[a].Name + "\">" + data[a].Name + "</a></li>";
            }

            break;
        }
        $("#area").html(content);
        //输出城市内容
        var city = $(this).attr("title").split("-")[0],
        content = "";
        if (ztocity.length > 0) {
            for (var i = 0,
                len = ztocity.length; i < len; i++)
                if (city == ztocity[i].Name) {
                    var data = ztocity[i].Data;
                    if (data != null && data != "" && data != "undefined") {
                        for (a = 0, alen = data.length; a < alen; a++) {
                            if (data[a].Order == "1") {
                                content += "<li> <a title=\"" + city + "-" + data[a].Name + "\">" + data[a].Name + "</a></li>";
                            } else {
                                content += "<li> <a class=\"not\" title=\"" + city + "-" + data[a].Name + "\">" + data[a].Name + "</a></li>";
                            }
                        }
                        break;
                    } else {
                        content += "<li style=\"width:100%;text-align:center\">没有找到记录</li>";
                    }
                }
        } 
    $("#city").html(content);

        //点击区县
        $("#area li a").not(".not").click(function () {
            var id = getCookie("loadPovincePageID");
            var pageid = getCookie("pageID");
            if (id == "Sender") {
                SetCookie("Sender", $("#Sender").val()); //始发省市区
            }
            if (id == "Receiver") {
                SetCookie("Receiver", $("#Receiver").val()); //目的省市区
            }
            if (pageid == null) {
                showMask("错误", "error", 1500);
                return;
            }
            $.ui.loadContent('#' + pageid + '', false, false, 'down');
            $("#" + id + "").val($(this).attr("title"));
            $("#area li a").removeClass("curr");
            $(this).addClass("curr");

            $(this).parent().parent().find("a").removeClass("curr"),
            $(this).addClass("curr"),
            $(".provinceMain>li").removeClass("curr"),
            $(".provinceMain>li").eq(0).addClass("curr"),
            $("#provinceNav li").removeClass("curr"),
            $("#provinceNav li").find(".Triangle").remove(),
            $("#provinceNav li").eq(0).prepend('<div class="Triangle">&nbsp;</div>'),
            $("#provinceNav li").eq(0).addClass("curr");
        });

})

//点击省份
$("#cprovince li a").not(".not").click(function () {
    $.ui.scrollToTop('provinceChangeOrder');
    $("#chotcity,#cprovince").find("a").removeClass("curr"),
    $(this).addClass("curr"),
    $(".provinceMain>li").removeClass("curr"),
    $(".provinceMain>li").eq(1).addClass("curr"),
    $("#provinceNav li").removeClass("curr"),
    $("#provinceNav li").find(".Triangle").remove(),
    $("#provinceNav li").eq(1).prepend('<div class="Triangle">&nbsp;</div>'),
    $("#provinceNav li").eq(1).addClass("curr");
    var city = $(this).attr("title").split("-")[0],
        content = "";
    for (var i = 0,
        len = ztocity.length; i < len; i++)
        if (city == ztocity[i].Name) {
            var data = ztocity[i].Data;
            if (data != null && data != "" && data != "undefined") {
                for (a = 0, alen = data.length; a < alen; a++)
                    if (data[a].Order == "1") {
                        content += "<li> <a title=\"" + city + "-" + data[a].Name + "\">" + data[a].Name + "</a></li>";
                    } else {
                        content += "<li> <a class=\"not\" title=\"" + city + "-" + data[a].Name + "\">" + data[a].Name + "</a></li>";
                    }
                break;
            } else {
                content += "<li style=\"width:100%;text-align:center\">没有找到记录</li>";
            }
        }

    $("#city").html(content);

        //点击城市文字
        $("#city li a").not(".not").click(function () {
            $(this).parent().parent().find("a").removeClass("curr"),
            $(this).addClass("curr"),
            $(".provinceMain>li").removeClass("curr"),
            $(".provinceMain>li").eq(2).addClass("curr"),
            $("#provinceNav li").removeClass("curr"),
            $("#provinceNav li").find(".Triangle").remove(),
            $("#provinceNav li").eq(2).prepend('<div class="Triangle">&nbsp;</div>'),
            $("#provinceNav li").eq(2).addClass("curr");
            var city = $(this).attr("title").split("-")[1],
            content = "";
            if (ztoarea.length > 0) {
                for (var i = 0,
                    len = ztoarea.length; i < len; i++)
                    if (city == ztoarea[i].Name) {
                        var data = ztoarea[i].Data;
                        if (data != null && data != "" && data != "undefined") {
                            for (a = 0, alen = data.length; a < alen; a++)
                                if (data[a].Order == "1") {
                                    content += "<li> <a  title=\"" + $(this).attr("title") + "-" + data[a].Name + "\">" + data[a].Name + "</a></li>";
                                } else {
                                    content += "<li> <a class=\"not\"  title=\"" + $(this).attr("title") + "-" + data[a].Name + "\">" + data[a].Name + "</a></li>";
                                }
                            break;
                        } else {
                            content += "<li style=\"width:100%;text-align:center\">没有找到记录</li>";
                        }
                    }
            }
            $("#area").html(content);

            //点击区县
            $("#area li a").not(".not").click(function () {
                var id = getCookie("loadPovincePageID");
                var pageid = getCookie("pageID");
                if (pageid == null) {
                    showMask("错误", "error", 1500);
                    return;
                }
                $.ui.loadContent('#' + pageid + '', false, false, 'down');
                $("#" + id + "").val($(this).attr("title"));
                if (id == "Sender") {
                    SetCookie("Sender", $("#Sender").val()); //始发省市区
                }
                if (id == "Receiver") {
                    SetCookie("Receiver", $("#Receiver").val()); //目的省市区
                }
                $("#area li a").removeClass("curr");
                $(this).addClass("curr");
                $.ui.scrollToTop('provinceChangeOrder')

                $(this).parent().parent().find("a").removeClass("curr"),
                $(this).addClass("curr"),
                $(".provinceMain>li").removeClass("curr"),
                $(".provinceMain>li").eq(0).addClass("curr"),
                $("#provinceNav li").removeClass("curr"),
                $("#provinceNav li").find(".Triangle").remove(),
                $("#provinceNav li").eq(0).prepend('<div class="Triangle">&nbsp;</div>'),
                $("#provinceNav li").eq(0).addClass("curr");
            });
        })
});
